home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
2499.ZIP
/
VERREG.ZIP
/
DEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-13
|
7KB
|
252 lines
/****************************************************************************
PROGRAM: Demo.c
PURPOSE: Demo template for Windows applications
FUNCTIONS:
WinMain() - calls initialization function, processes message loop
DemoInit() - initializes window data and registers window
DemoWndProc() - processes messages
About() - processes messages for "About" dialog box
****************************************************************************/
#define NOCOMM
#define NOMINMAX
#include "windows.h" /* required for all Windows applications */
#include "Demo.h" /* specific to this program */
HANDLE hInst; /* current instance */
HANDLE hWndMain; /* handle to the main window */
HANDLE hMenu; /* Handle to my new menu */
FARPROC lpfnFarProc; /* farproc handle for dialogs */
#pragma alloc_text( WINMAIN, WinMain )
#pragma alloc_text( DemoIN, DemoInit )
#pragma alloc_text( DemoPROC, DemoWndProc )
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
COMMENTS:
This will initialize the window class if it is the first time this
application is run. It then creates the window, and processes the
message loop until a PostQuitMessage is received. It exits the
application by returning the value passed by the PostQuitMessage.
****************************************************************************/
int PASCAL WinMain( HANDLE hInstance,
HANDLE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
/* current instance */
/* previous instance */
/* command line */
/* show-window type (open/icon) */
{
MSG msg; /* message */
if (!DemoInit( hInstance, hPrevInstance, nCmdShow ))
return (NULL); /* Exits if unable to initialize */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window receiving the message */
NULL, /* lowest message to examine */
NULL)) /* highest message to examine */
{
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
return (msg.wParam); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: DemoInit
PURPOSE: Initializes window data and registers window class
****************************************************************************/
BOOL DemoInit( HANDLE hInstance, HANDLE hPrevInstance, int nCmdShow )
/* current instance */
/* previous instance */
/* default window status */
{
HANDLE hMemory; /* handle to allocated memory */
PWNDCLASS pWndClass; /* structure pointer */
BOOL bSuccess; /* RegisterClass() result */
HWND hWnd; /* window handle */
if ( !hPrevInstance ) {
hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
pWndClass = (PWNDCLASS) LocalLock(hMemory);
pWndClass->style = CS_VREDRAW | CS_HREDRAW;
pWndClass->lpfnWndProc = DemoWndProc;
pWndClass->hInstance = hInstance;
pWndClass->hIcon = NULL;
pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
pWndClass->lpszMenuName = (LPSTR) "Demo";
pWndClass->lpszClassName = (LPSTR) "Demo";
pWndClass->cbClsExtra = NULL;
pWndClass->cbWndExtra = NULL;
bSuccess = RegisterClass(pWndClass);
LocalUnlock(hMemory); /* Unlocks the memory */
LocalFree(hMemory); /* Returns it to Windows */
// if registering the window class failed then return FALSE
if ( !bSuccess )
return( NULL );
}
hInst = hInstance; /* Saves the current instance */
hMenu = LoadMenu(hInstance, "DemoMenu");
hWnd = CreateWindow("Demo", /* window class */
"Demo", /* window name */
WS_OVERLAPPEDWINDOW, /* window style */
CW_USEDEFAULT, /* x position */
CW_USEDEFAULT, /* y position */
CW_USEDEFAULT, /* width */
CW_USEDEFAULT, /* height */
NULL, /* parent handle */
hMenu, /* menu or child ID*/
hInstance, /* instance */
NULL); /* additional info */
if (!hWnd) /* Was the window created? */
return (NULL);
hWndMain = hWnd; /* save the handle to the main window */
ShowWindow(hWnd, nCmdShow); /* Shows the window */
UpdateWindow(hWnd); /* Sends WM_PAINT message */
return ( TRUE ); /* Returns result of registering the window */
}
/****************************************************************************
FUNCTION: DemoWndProc
PURPOSE: Processes messages for the main window
MESSAGES:
WM_CREATE - create window
WM_DESTROY - destroy window
WM_COMMAND - menu selections and others
COMMENTS:
****************************************************************************/
DWORD FAR PASCAL DemoWndProc( HWND hWnd, /* window handle */
WORD message, /* type of message */
WORD wParam, /* additional information */
DWORD lParam) /* additional information */
{
switch (message) {
case WM_CREATE: /* message: window being created */
// window initialization goes here
break;
case WM_DESTROY: /* message: window being destroyed */
PostQuitMessage(0);
break;
case WM_COMMAND:
switch (wParam) {
case IDM_ABOUT: // creates a modal dialog
lpfnFarProc = MakeProcInstance ( DemoDlgProc1, hInst );
DialogBox( hInst, "DEMODLG", hWnd, lpfnFarProc );
FreeProcInstance( lpfnFarProc );
break; // case IDM_ABOUT
}
break;
default: /* Passes it on if unproccessed */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return( FALSE );
}
BOOL FAR PASCAL DemoDlgProc1( HWND hDlg,
WORD iMessage,
WORD wParam,
DWORD lParam )
{
char Temp[60];
switch (iMessage)
{
case WM_INITDIALOG:
// should return false if the focus is set to a control by this
// function
LoadString( hInst, IDS_NUMBER, (LPSTR) Temp, NUMBER+1 );
SetDlgItemText( hDlg, 108, Temp );
LoadString( hInst, IDS_NAME, (LPSTR) Temp, NAME+1 );
SetDlgItemText( hDlg, 110, Temp );
break;
case WM_COMMAND:
EndDialog( hDlg, 0 );
break; // ID_CANCEL
default: // iMessage switch
return FALSE ;
} // iMessage switch
return( TRUE );
}